#ifndef SLAVE_H_
#define SLAVE_H_

#include "BlockStorage.h"
#include "mpi.h"

class Slave {
public:
    virtual void run();
    virtual void serveBlocks();
    
protected:
    virtual void sendAssignmentRequest();
    virtual void listenForNextIterationSignal();
    virtual void listenForTerminationSignal();
    virtual void listenForBlockAssignment();
    virtual bool shouldEndIteration();
    virtual bool shouldTerminate();
    virtual bool hasWorkAssigned();
    
    virtual void performIteration();
    virtual void updateBlock() = 0;
    
    virtual void resetWorkingBlockId();
    
    int working_block_id;
    MPI_Request block_assignment, next_iteration_signal, termination_signal;
    MPI_Status status;
    int nothing, flag;
    BlockStorage* storage;
};

#endif
